# PyOpenSG is (C) Copyright 2005-2009 by Allen Bierbaum
#
# This file is part of PyOpenSG.
#
# PyOpenSG is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# PyOpenSG is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
# more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# pyplusplus script
#
import sys, re, os, os.path, time, logging, glob, copy, distutils.sysconfig
pj = os.path.join
import pygccxml
from pyplusplus import module_builder
from pygccxml import parser

# Setup global settings
import pyplusplus.code_creators.calldef
pyplusplus.code_creators.calldef.use_enum_workaround = True

output_dir = "osg_module_temp"
gccxml_file = "gccxml_file.xml"
cache_file = "pypp.pyopensg_temp.cache"

if not os.path.exists(gccxml_file):
   # --- Collect all settings for build ---- #
   opensg_inc_dir = os.path.join(os.popen('osg2-config --prefix','r').readline().strip(),
                                 'include')
   opensg_cflags = os.popen('osg2-config --cflags System Base','r').readline().strip()
   opensg_cflags = opensg_cflags.replace("-use_readonly_const","")
   
   opensg_src_dir = "/home/allenb/Source/OpenSG2/Source"                           
   boost_inc_dir = "/home/allenb/Source/boost"
   python_inc_dir = distutils.sysconfig.get_python_inc()
   defines = []                 
   gccxml_path = ""
   inc_path = [output_dir, opensg_inc_dir, pj(opensg_inc_dir,"OpenSG"), boost_inc_dir, python_inc_dir]
   
   # ------ Manually define headers files -------- #
   # These includes are added later to the module builder
   extra_includes = ["boost/python/suite/indexing/map_indexing_suite.hpp",
                     "boost/python/suite/indexing/vector_indexing_suite.hpp"]
   all_headers = ["OpenSG/OSGNode.h"]
else:
   all_headers = [parser.create_gccxml_fc(gccxml_file)]
   inc_path = []
   opensg_cflags = []
   defines = []
   
mb = module_builder.module_builder_t(all_headers,
                   working_directory = ".",
                   include_paths=inc_path,
                   cache=cache_file+".module",                                        
                   define_symbols=defines,
                   ignore_gccxml_output=True,
                   optimize_queries=False,                                     
                   cflags=opensg_cflags)
                   #dependent_headers=all_headers_full_paths)
mb.global_ns.exclude()
osg = mb.global_ns.namespace("OSG", recursive=False)

# Public methods
for m in ["cloneTree","deepCloneTree"]:
   print "m: %s"%m
   funcs = osg.decls(m)
   funcs.include()
   funcs.use_overload_macro = True


#Now it is the time to give a name to our module
mb.build_code_creator(module_name='_osg2', enable_indexing_suite=False, )
#mb.code_creator.user_defined_directories.append(opensg_inc_dir)
mb.code_creator.add_namespace_usage('std')

mb.split_module(pj(output_dir,'generated'))





